<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Finance extends Model
{
    //
    const TYPE_TOP_UP = 1;//充值
    const TYPE_ORDER = 2;//下单
    const TYPE_WATER = 3;//水费
    const TYPE_ELECTRIC = 4;//电费
    const TYPE_RENT = 5;//房屋租金
    const TYPE_SALARY = 6;//员工工资
    const TYPE_OTHER = 7;//其他支出
    public static $mapIncomeType = [
        self::TYPE_TOP_UP => [
            'label' => '充值',
            'value' => self::TYPE_TOP_UP
        ],
        self::TYPE_ORDER => [
            'label' => '下单',
            'value' => self::TYPE_ORDER
        ]
    ];
    public static $mapExpendType = [
        self::TYPE_WATER => [
            'label' => '水费',
            'value' => self::TYPE_WATER
        ],
        self::TYPE_ELECTRIC => [
            'label' => '电费',
            'value' => self::TYPE_ELECTRIC
        ],
        self::TYPE_RENT => [
            'label' => '房租',
            'value' => self::TYPE_RENT
        ],
        self::TYPE_SALARY => [
            'label' => '工资',
            'value' => self::TYPE_SALARY
        ],
        self::TYPE_OTHER => [
            'label' => '其他支出',
            'value' => self::TYPE_OTHER
        ]
    ];
    public static $mapType = [
        self::TYPE_TOP_UP => [
            'label' => '充值',
            'value' => self::TYPE_TOP_UP
        ],
        self::TYPE_ORDER => [
            'label' => '下单',
            'value' => self::TYPE_ORDER
        ],
        self::TYPE_WATER => [
            'label' => '水费',
            'value' => self::TYPE_WATER
        ],
        self::TYPE_ELECTRIC => [
            'label' => '电费',
            'value' => self::TYPE_ELECTRIC
        ],
        self::TYPE_RENT => [
            'label' => '房租',
            'value' => self::TYPE_RENT
        ],
        self::TYPE_SALARY => [
            'label' => '工资',
            'value' => self::TYPE_SALARY
        ],
        self::TYPE_OTHER => [
            'label' => '其他支出',
            'value' => self::TYPE_OTHER
        ]
    ];
    public static $mapExpendRule = [
        self::TYPE_WATER,
        self::TYPE_ELECTRIC,
        self::TYPE_RENT,
        self::TYPE_SALARY,
        self::TYPE_OTHER
    ];
    protected $fillable = [
        'seller_id',
        'amount',
        'desc',
        'type',
        'generated_at',
        'is_income'
    ];
    protected $appends = [
        'type_name'
    ];

    public function getTypeNameAttribute()
    {
        if(isset($this->attributes['type'])){
            return self::$mapType[$this->attributes['type']]['label'] ?? '';
        }else{
            return '';
        }
    }
}
